import { IExternalData } from './../../components/interfaces/external-data';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { DataType } from '../../components/interfaces/data-type'
import { Data } from '../../components/interfaces/data'
import { Subscriber } from "rxjs/Subscriber";

@Injectable()
export class AddressDataTWService implements IExternalData {

    constructor() {
    }

    private get provinces(): Data {
        return {
            type: DataType.list,
            list: [{"id":"712800","name":"连江"},{"id":"710200","name":"高雄"},{"id":"712600","name":"花莲"},{"id":"710900","name":"嘉义"},{"id":"711900","name":"嘉义"},{"id":"710700","name":"基隆"},{"id":"710500","name":"金门"},{"id":"711500","name":"苗栗"},{"id":"710600","name":"南投"},{"id":"712700","name":"澎湖"},{"id":"712400","name":"屏东"},{"id":"710100","name":"台北"},{"id":"712500","name":"台东"},{"id":"710300","name":"台南"},{"id":"710400","name":"台中"},{"id":"711400","name":"桃园"},{"id":"711100","name":"新北"},{"id":"710800","name":"新竹"},{"id":"711300","name":"新竹"},{"id":"711200","name":"宜兰"},{"id":"712100","name":"云林"},{"id":"711700","name":"彰化"}]
        };
    };

    private get cities(): Array<any> {
        return [["712806","北竿","712800"],["712808","东引","712800"],["712807","莒光","712800"],["712805","南竿","712800"],["710246","阿莲","710200"],["710255","大寮","710200"],["710243","大社","710200"],["710258","大树","710200"],["710254","凤山","710200"],["710244","冈山","710200"],["710253","湖内","710200"],["710264","甲仙","710200"],["710241","苓雅","710200"],["710256","林园","710200"],["710261","六龟","710200"],["710245","路竹","710200"],["710267","茂林","710200"],["710260","美浓","710200"],["710251","弥陀","710200"],["710266","那玛夏","710200"],["710262","内门","710200"],["710257","鸟松","710200"],["710249","桥头","710200"],["710268","茄萣","710200"],["710259","旗山","710200"],["710242","仁武","710200"],["710263","杉林","710200"],["710265","桃源","710200"],["710247","田寮","710200"],["710248","燕巢","710200"],["710252","永安","710200"],["710250","梓官","710200"],["710205","鼓山","710200"],["710210","楠梓","710200"],["710202","前金","710200"],["710207","前镇","710200"],["710206","旗津","710200"],["710203","芩雅","710200"],["710208","三民","710200"],["710211","小港","710200"],["710201","新兴","710200"],["710204","盐埕","710200"],["710209","左营","710200"],["712623","丰滨","712600"],["712621","凤林","712600"],["712628","富里","712600"],["712622","光复","712600"],["712615","花莲","712600"],["712627","卓溪","712600"],["712619","吉安","712600"],["712624","瑞穗","712600"],["712620","寿丰","712600"],["712616","新城","712600"],["712618","秀林","712600"],["712617","太鲁","712600"],["712625","万荣","712600"],["712626","玉里","712600"],["710901","东区","710900"],["710902","西区","710900"],["711922","阿里山","711900"],["711926","鹿草","711900"],["711936","布袋","711900"],["711933","大林","711900"],["711924","大埔","711900"],["711929","东石","711900"],["711919","番路","711900"],["711923","中埔","711900"],["711921","竹崎","711900"],["711930","六脚","711900"],["711920","梅山","711900"],["711932","民雄","711900"],["711928","朴子","711900"],["711925","水上","711900"],["711934","溪口","711900"],["711931","新港","711900"],["711927","太保","711900"],["711935","义竹","711900"],["710705","安乐","710700"],["710706","暖暖","710700"],["710707","七堵","710700"],["710701","仁爱","710700"],["710702","信义","710700"],["710704","中山","710700"],["710703","中正","710700"],["710510","金城","710500"],["710508","金湖","710500"],["710509","金宁","710500"],["710507","金沙","710500"],["710511","烈屿","710500"],["710512","乌坵","710500"],["711531","大湖","711500"],["711530","公馆","711500"],["711524","后龙","711500"],["711519","竹南","711500"],["711536","卓兰","711500"],["711527","苗栗","711500"],["711522","南庄","711500"],["711521","三湾","711500"],["711534","三义","711500"],["711523","狮潭","711500"],["711535","西湖","711500"],["711532","泰安","711500"],["711533","铜锣","711500"],["711525","通霄","711500"],["711520","头份","711500"],["711529","头屋","711500"],["711526","苑里","711500"],["711528","造桥","711500"],["710616","草屯","710600"],["710617","国姓","710600"],["710615","中寮","710600"],["710625","竹山","710600"],["710621","集集","710600"],["710626","鹿谷","710600"],["710620","名间","710600"],["710614","南投","710600"],["710618","埔里","710600"],["710619","仁爱","710600"],["710622","水里","710600"],["710624","信义","710600"],["710623","鱼池","710600"],["712711","白沙","712700"],["712710","七美","712700"],["712712","湖西","712700"],["712707","马公","712700"],["712708","西屿","712700"],["712709","望安","712700"],["712442","长治","712400"],["712447","潮州","712400"],["712463","车城","712400"],["712461","春日","712400"],["712455","东港","712400"],["712459","枋寮","712400"],["712460","枋山","712400"],["712440","高树","712400"],["712465","恒春","712400"],["712444","竹田","712400"],["712457","佳冬","712400"],["712438","九如","712400"],["712451","崁顶","712400"],["712449","来义","712400"],["712439","里港","712400"],["712454","林边","712400"],["712443","麟洛","712400"],["712456","琉球","712400"],["712437","玛家","712400"],["712466","满州","712400"],["712464","牡丹","712400"],["712453","南州","712400"],["712445","内埔","712400"],["712434","屏东","712400"],["712435","三地门","712400"],["712462","狮子","712400"],["712452","新埤","712400"],["712458","新园","712400"],["712448","泰武","712400"],["712446","万丹","712400"],["712450","万峦","712400"],["712436","雾台","712400"],["712441","盐埔","712400"],["710109","北投","710100"],["710105","大安","710100"],["710102","大同","710100"],["710111","南港","710100"],["710110","内湖","710100"],["710107","信义","710100"],["710108","士林","710100"],["710104","松山","710100"],["710106","万华","710100"],["710112","文山","710100"],["710103","中山","710100"],["710101","中正","710100"],["712521","卑南","712500"],["712528","长滨","712500"],["712527","成功","712500"],["712525","池上","712500"],["712531","达仁","712500"],["712530","大武","712500"],["712526","东河","712500"],["712523","关山","712500"],["712524","海端","712500"],["712529","金峰","712500"],["712519","兰屿","712500"],["712522","鹿野","712500"],["712518","绿岛","712500"],["712517","台东","712500"],["712532","太麻里","712500"],["712520","延平","712500"],["710369","安定","710300"],["710359","白河","710300"],["710356","北门","710300"],["710366","大内","710300"],["710360","东山","710300"],["710347","关庙","710300"],["710349","官田","710300"],["710340","归仁","710300"],["710358","后壁","710300"],["710351","佳里","710300"],["710354","将军","710300"],["710361","六甲","710300"],["710363","柳营","710300"],["710348","龙崎","710300"],["710350","麻豆","710300"],["710345","南化","710300"],["710344","楠西","710300"],["710353","七股","710300"],["710346","仁德","710300"],["710365","善化","710300"],["710367","山上","710300"],["710362","下营","710300"],["710352","西港","710300"],["710341","新化","710300"],["710368","新市","710300"],["710357","新营","710300"],["710355","学甲","710300"],["710364","盐水","710300"],["710339","永康","710300"],["710343","玉井","710300"],["710342","左镇","710300"],["710306","安南","710300"],["710305","安平","710300"],["710304","北区","710300"],["710302","东区","710300"],["710303","南区","710300"],["710301","中西","710300"],["710451","大安","710400"],["710444","大肚","710400"],["710449","大甲","710400"],["710432","大里","710400"],["710442","大雅","710400"],["710438","东势","710400"],["710435","丰原","710400"],["710439","和平","710400"],["710436","后里","710400"],["710446","龙井","710400"],["710448","清水","710400"],["710445","沙鹿","710400"],["710443","神冈","710400"],["710437","石冈","710400"],["710431","太平","710400"],["710441","潭子","710400"],["710450","外埔","710400"],["710433","雾峰","710400"],["710447","梧栖","710400"],["710434","乌日","710400"],["710440","新社","710400"],["710405","北区","710400"],["710406","北屯","710400"],["710402","东区","710400"],["710403","南区","710400"],["710408","南屯","710400"],["710404","西区","710400"],["710407","西屯","710400"],["710401","中区","710400"],["711422","八德","711400"],["711423","大溪","711400"],["711425","大园","711400"],["711424","复兴","711400"],["711419","观音","711400"],["711421","龟山","711400"],["711414","中坜","711400"],["711416","龙潭","711400"],["711426","芦竹","711400"],["711415","平镇","711400"],["711418","新屋","711400"],["711420","桃园","711400"],["711417","杨梅","711400"],["711155","八里","711100"],["711132","板桥","711100"],["711156","淡水","711100"],["711139","贡寮","711100"],["711144","中和","711100"],["711131","金山","711100"],["711152","林口","711100"],["711153","芦洲","711100"],["711141","坪林","711100"],["711137","平溪","711100"],["711136","瑞芳","711100"],["711149","三重","711100"],["711157","三芝","711100"],["711146","三峡","711100"],["711134","深坑","711100"],["711135","石碇","711100"],["711158","石门","711100"],["711138","双溪","711100"],["711147","树林","711100"],["711133","汐止","711100"],["711140","新店","711100"],["711150","新庄","711100"],["711151","泰山","711100"],["711145","土城","711100"],["711130","万里","711100"],["711154","五股","711100"],["711142","乌来","711100"],["711148","莺歌","711100"],["711143","永和","711100"],["710802","北区","710800"],["710801","东区","710800"],["710803","香山","710800"],["711320","宝山","711300"],["711325","北埔","711300"],["711319","芎林","711300"],["711326","峨眉","711300"],["711318","关西","711300"],["711323","横山","711300"],["711315","湖口","711300"],["711314","竹北","711300"],["711321","竹东","711300"],["711324","尖石","711300"],["711316","新丰","711300"],["711317","新埔","711300"],["711322","五峰","711300"],["711221","大同","711200"],["711223","冬山","711200"],["711217","壮围","711200"],["711216","礁溪","711200"],["711219","罗东","711200"],["711225","南澳","711200"],["711220","三星","711200"],["711224","苏澳","711200"],["711215","头城","711200"],["711222","五结","711200"],["711214","宜兰","711200"],["711218","员山","711200"],["711226","钓鱼","711200"],["712125","褒忠","712100"],["712136","北港","712100"],["712133","莿桐","712100"],["712122","大埤","712100"],["712126","东势","712100"],["712130","斗六","712100"],["712121","斗南","712100"],["712135","二仑","712100"],["712132","古坑","712100"],["712123","虎尾","712100"],["712138","口湖","712100"],["712131","林内","712100"],["712128","仑背","712100"],["712129","麦寮","712100"],["712137","水林","712100"],["712139","四湖","712100"],["712134","西螺","712100"],["712127","台西","712100"],["712124","土库","712100"],["712140","元长","712100"],["711744","北斗","711700"],["711750","大城","711700"],["711741","大村","711700"],["711749","二林","711700"],["711752","二水","711700"],["711751","芳苑","711700"],["711728","芬园","711700"],["711732","福兴","711700"],["711734","和美","711700"],["711729","花坛","711700"],["711727","彰化","711700"],["711748","竹塘","711700"],["711731","鹿港","711700"],["711746","埤头","711700"],["711739","埔心","711700"],["711742","埔盐","711700"],["711735","伸港","711700"],["711737","社头","711700"],["711733","线西","711700"],["711740","溪湖","711700"],["711747","溪州","711700"],["711730","秀水","711700"],["711743","田中","711700"],["711745","田尾","711700"],["711738","永靖","711700"],["711736","员林","711700"]];
    }

    private cachedMap: any = {

    };

    public getTypes(): Array<string> {
        return [ '城市', '县区' ];
    }

    public getJumps(): Array<string> {
        return [];
    }

    public getData(index: number, id: string): Observable<Data> {
        return new Observable(observer => {
            if (index > 1) {
                observer.next(null);
                observer.complete();
                return;
            }
            if (!id) {
                observer.next(this.provinces);
                observer.complete();
                return;
            }

            let _c = this.cachedMap[id];
            if (!_c) {
                _c = {
                    type: DataType.list,
                    list: this.cities.filter((value, index) => {
                        return value[2] == id;
                    }).map(item => {
                        let res: any = {
                            id: item[0],
                            name: item[1]
                        };
                        if (item[3] === '3')
                            res.tips = true;
                        return res;
                    })
                };

                this.cachedMap[id] = _c;
            }

            observer.next(_c);
            observer.complete();
        });
    }

    public setAddress(data: any): Observable<string[]> {
        return new Observable(observer => {
            observer.next();
            observer.complete();
        });
    }
}

